WebRTC peer-to-peer implementation for UTCP
The WebRTC provider enables UTCP to establish peer-to-peer connections for real-time communication, allowing for direct data exchange between clients without requiring a central server for data transfer. This is ideal for applications requiring low-latency, direct communication between peers.
WebRTC providers are configured using the following JSON structure:
{ "name": "p2p_service", "provider_type": "webrtc", "signaling_server": "wss://signaling.example.com/socket", "peer_id": "server-endpoint-123", "data_channel_name": "tools", "ice_servers": [ { "urls": ["stun:stun.l.google.com:19302"] }, { "urls": ["turn:turn.example.com:3478"], "username": "user", "credential": "pass" } ], "connection_timeout": 30000, "ordered": true, "max_retransmits": 3 }
Field | Required | Description |
---|---|---|
name |
Yes | Unique identifier for the provider |
provider_type |
Yes | Must be set to "webrtc" |
signaling_server |
Yes | WebSocket URL of the signaling server |
peer_id |
Yes | ID of the peer to connect to |
data_channel_name |
No | Name of the data channel (default: "tools" ) |
ice_servers |
No | STUN/TURN servers for NAT traversal |
connection_timeout |
No | Connection timeout in milliseconds (default: 30000 ) |
ordered |
No | Whether messages should be delivered in order (default: true ) |
max_retransmits |
No | Maximum number of retransmissions (default: 3 ) |
WebRTC requires a signaling mechanism to establish connections. The process typically works as follows:
Both peers connect to the signaling server via WebSocket
The client initiates a connection request with an offer
The server responds with an answer to the offer
ICE candidates are exchanged to establish the best connection path
Once established, data flows directly between peers
Messages sent over the WebRTC data channel should follow a standard format:
{ "type": "tool_call", "tool": "tool_name", "id": "unique-call-id", "inputs": { "param1": "value1", "param2": "value2" } }
{ "type": "tool_response", "tool": "tool_name", "id": "unique-call-id", "output": { "result": "value" } }
For WebRTC providers, tool discovery can happen in two ways:
The initial tool definitions are provided through the signaling server during the connection handshake.
Tool definitions are requested after the WebRTC connection is established using the data channel.
{ "name": "game_p2p", "provider_type": "webrtc", "signaling_server": "wss://game-signal.example.com/socket", "peer_id": "game-server-789", "data_channel_name": "gamedata", "ordered": true, "max_retransmits": 0, "ice_servers": [ { "urls": ["stun:stun.l.google.com:19302"] } ] }
{ "name": "document_collaboration", "provider_type": "webrtc", "signaling_server": "wss://collab.example.com/signal", "peer_id": "doc-server-456", "data_channel_name": "document", "ordered": true, "connection_timeout": 60000, "ice_servers": [ { "urls": ["stun:stun.l.google.com:19302"] }, { "urls": ["turn:turn.example.com:3478"], "username": "collab_user", "credential": "secure_pass" } ] }
{ "name": "video_conference", "provider_type": "webrtc", "signaling_server": "wss://meet.example.com/signal", "peer_id": "conference-room-123", "data_channel_name": "controls", "ordered": false, "max_retransmits": 1, "connection_timeout": 45000 }
© 2024 Universal Tool Calling Protocol. All rights reserved.